/* Copyright (C) 2007-2008  klevgert  http://code.google.com/p/db4o-netbeans/

This file is part of the db4o-netbeans module suite.

db4o-netbeans is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation and as clarified by db4objects' GPL 
interpretation policy, available at
http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
Suite 350, San Mateo, CA 94403, USA.

db4o-netbeans is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */


package com.db4o.nb.api;

import com.db4o.ObjectContainer;
import java.beans.PropertyChangeListener;

/**
 * Represents a db4o database in the sense of the net beans plugin. 
 * Encapsulates the object container as well as the file/server to connect to.
 * 
 * @author klevgert
 */
public interface Db4oDatabase {
  
  /**
   * Gets the db4o root object.
   * @return db4o provider 
   */
  public Db4oProvider    getProvider();
  
  /**
   * Gets the encapsulated db4o object container.
   * @return db4o object container
   */
  public ObjectContainer getObjectContainer();
  
  /**
   * Gets the custom name for the databse connection.
   * @return custom name
   */
  public String          getName();
  
  /**
   * Sets the custom name for the databse connection.
   * @param name    custom name
   */
  public void            setName( String name );

  /**
   * Gets the name of the db4o file.
   * @return db4o file name
   */
  public String          getFile();
  
  /**
   * Sets the name of the db4o file to open.
   * @param file   db4o file name
   */
  public void            setFile( String file );
 
  /**
   * Gets the host name or ip of the db4o object server to connect to.
   * @return name of host
   */
  public String          getHost();
  
  /**
   * Sets the host name or ip of the db4o object server to connect to.
   * @param host   name of host
   */
  public void            setHost( String host );

  /**
   * Gets the stringified port number for connection to the db4o server.
   * @return port number as a string. 
   */
  public String          getPort();
  
  /**
   * Sets the stringified port number for connection to the db4o server.
   * @param port   port number as a string. 
   */
  public void            setPort( String port );

  /**
   * Gets the user name for authentication .
   * @return user name. 
   */
  public String          getUser();
  
  /**
   * Sets the user name for authentication .
   * @param user   user name. 
   */
  public void            setUser( String user );

  /**
   * Gets the password for authentication.
   * @return password. 
   */
  public String          getPassword();

  /**
   * Sets the password for authentication.
   * @param pwd   password. 
   */
  public void            setPassword( String pwd );
  
  /**
   * Gets the flag if the database should be connected read-only.
   * @return true if open read only, otherwise false. 
   */
  public boolean         isReadOnly();
  
  /**
   * Sets the flag that the database should be connected read-only.
   * @param readOnly   true if open read only, otherwise false. 
   */
  public void            setReadOnly(boolean readOnly);

  /**
   * Flag that is true if the database should be version updated automatically.
   * @return true if database version should be updated, otherwise false. 
   */
  public boolean         isAllowVersionUpdate();

  /**
   * Sets the flag to update version of database automatically.
   * @param versionUpdate    true, if version to update.
   */
  public void            setAllowVersionUpdate(boolean versionUpdate);
  
  /**
   * Connects to the db4o file or object server with the values specified.
   * @return db4o object container for the opened db4o file/server. 
   */
  public ObjectContainer connect();
  
  /**
   * Disconnects from the db4o file or object server with the specified values.
   */
  public void disconnect();
  
  /**
   * Checks if this object is currently connected.
   * @return true, if connected, otherwise false.
   */
  public boolean isConnected();
  
  /**
   * Checks if this object is already configured, i.e. a file or object server details are
   * set.
   * @return true, if configured, otherwise false.
   */
  public boolean isConfigured();
  
  /**
   * Clears all values.
   */
  public void reset();

  /**
   * Send a message to the server
   * @param message   message object to provide to server.
   */
  public void sendMessage( Object message );

  /**
   * Add a listener for property changes.
   * @param listener   listener object to add.
   */
  public void addPropertyChangeListener(PropertyChangeListener listener);
  
  /**
   * Remove a previous added listener for property changes.
   * @param listener   listener object to remove
   */
  public void removePropertyChangeListener(PropertyChangeListener listener);

}
